package com.yd.tool;


public class ShengCheng {
	public static void main(String[] args) {
		String dbname=strdbname_banner;
		String dbc=strdbname_banner2;
		System.out.println(getPojo(dbname,dbc));
		System.out.println(getMapper(dbname));
		System.out.println(getService(dbname));
		System.out.println(getServiceImpl(dbname));
		System.out.println(getMybatis(dbname,dbc));
	}
	
	
	public static String strdbname_users="users";
	public static String strdbname_users2="`id int"+
									  "`tid int"+
									  "`tpid int"+
									  "`loginname varchar"+
									  "`loginpass varchar"+
									  "`phone varchar"+
									  "`shenhezhuangtai char"+
									  "`moneydangqian decimal"+
									  "`moneydonjie decimal"+
									  "`names varchar"+
									  "`jingjigongsibm varchar"+
									  "`mingpianimg varchar"+
									  "`touxiangimg varchar"+
									  "`chengshi varchar"+
									  "`usersname varchar"+
									  "`password varchar"+
									  "`passkey varchar"+
									  "`note varchar"+
									  "`delid char"+
									  "`state char"+
									  "`sort char"+
									  "`addtime datetime"+
									  "`uptime datetime";
	
	
	public static String strdbname_uloginrecord="uloginrecord";
	public static String strdbname_uloginrecord2="`id int"+
										  "`tid int"+
										  "`loginname varchar"+
										  "`ip varchar"+
										  "`note varchar"+
										  "`delid char"+
										  "`state char"+
										  "`sort char"+
										  "`addtime datetime"+
										  "`uptime datetime";
	
	
	
	public static String strdbname_newsinfo="newsinfo";
	public static String strdbname_newsinfo2="`id int"+
									  "`tid int"+
									  "`tpid int"+
									  "`info LongText"+
									  "`note varchar"+
									  "`delid char"+
									  "`state char"+
									  "`sort char"+
									  "`addtime datetime"+
									  "`uptime datetime";
	
	public static String strdbname_news="news";
	public static String strdbname_news2="`id int"+
								  "`tid int"+
								  "`tpid int"+
								  "`title varchar"+
								  "`img varchar"+
								  "`doc varchar"+
								  "`cityid int"+
								  "`ishot char"+
								  "`istop char"+
								  "`clicknum int"+
								  "`note varchar"+
								  "`delid char"+
								  "`state char"+
								  "`sort char"+
								  "`addtime datetime"+
								  "`uptime datetime";
	
	
	
	public static String strdbname_banner="banner";
	public static String strdbname_banner2="`id int"+
									  "`tid int"+
									  "`tpid int"+
									  "`title varchar"+
									  "`img varchar"+
									  "`url varchar"+
									  "`cityid int"+
									  "`isinfo char"+
									  "`info LongText"+
									  "`note varchar"+
									  "`delid char"+
									  "`state char"+
									  "`sort char"+
									  "`addtime datetime"+
									  "`uptime datetime";
	
	public static String strdbname_citys="citys";
	public static String strdbname_citys2="`id int"+
									  "`title varchar"+
									  "`tid char"+
									  "`pid char"+
									  "`ison char"+
									  "`shouzimu varchar"+
									  "`quanpin varchar";
	
	//public
	public static String getPojo(String dbname,String dbinfo){
		System.out.println("\n");
		System.err.println("----Pojo----"+shouzimudaxie(dbname));
		String str="package com.yd.pojo;";
		str+="import java.io.Serializable;";
		str+="import com.baomidou.mybatisplus.activerecord.Model;";
		str+="import com.baomidou.mybatisplus.annotations.TableId;";
		str+="import com.baomidou.mybatisplus.annotations.TableName;";
		str+="import com.baomidou.mybatisplus.enums.IdType;";
		str+="@TableName(\""+shouzimudaxie(dbname)+"\") ";
		str+="public class "+shouzimudaxie(dbname)+" extends Model<"+shouzimudaxie(dbname)+"> {";

		str+="private static final long serialVersionUID = 1L;";
		str+="@TableId(value = \"id\", type = IdType.AUTO) ";
				
			String[] arrstr=dbinfo.split("`");
			for (int i = 0; i < arrstr.length; i++) {
				if(arrstr[i].length()>0){
					String[] arrstr2=arrstr[i].split(" ");
					str+="private "+zhuanhuan(arrstr2[1])+" "+arrstr2[0]+";";
				}
				
			}
			
			str+="@Override "+
				  "protected Serializable pkVal() {"+
					"return this.id;"+
				  "}";
				
			str+="}";
		
		return str;
	}
	public static String getMapper(String dbname){
		System.out.println("\n");
		System.err.println("----Mapper----"+shouzimudaxie(dbname)+"Mapper");
		String str="package com.yd.mapper;";
		str+="import java.util.List;";
		str+="import org.apache.ibatis.annotations.Param;";
		str+="import com.baomidou.mybatisplus.mapper.BaseMapper;";
		str+="import com.yd.pojo."+shouzimudaxie(dbname)+";";
		str+="public interface "+shouzimudaxie(dbname)+"Mapper extends BaseMapper<"+shouzimudaxie(dbname)+"> {";
		
		str+="List<"+shouzimudaxie(dbname)+"> find"+shouzimudaxie(dbname)+"List();";
		
		str+="}";
		
		return str;
	}
	public static String getService(String dbname){
		System.out.println("\n");
		System.err.println("----Service----"+shouzimudaxie(dbname)+"Service");
		String str="package com.yd.service;";
		str+="import java.util.List;";
		str+="import com.baomidou.mybatisplus.service.IService;";
		str+="import com.yd.pojo."+shouzimudaxie(dbname)+";";
		str+="public interface "+shouzimudaxie(dbname)+"Service extends IService<"+shouzimudaxie(dbname)+"> {";
		
		str+="List<"+shouzimudaxie(dbname)+"> find"+shouzimudaxie(dbname)+"List();";

		str+="}";
		
		return str;
	}
	public static String getServiceImpl(String dbname){
		System.out.println("\n");
		System.err.println("----ServiceImpl----"+shouzimudaxie(dbname)+"Impl");
		String str="package com.yd.service.impl;";
		
		str+="import java.util.List;";
		str+="import javax.annotation.Resource;";
		str+="import org.springframework.stereotype.Service;";
		str+="import com.baomidou.mybatisplus.service.impl.ServiceImpl;";
		str+="import com.yd.mapper."+shouzimudaxie(dbname)+"Mapper;";
		str+="import com.yd.pojo."+shouzimudaxie(dbname)+";";
		str+="import com.yd.service."+shouzimudaxie(dbname)+"Service;";
		str+="@Service ";
		str+="\n";
		str+="public class "+shouzimudaxie(dbname)+"Impl extends ServiceImpl<"+shouzimudaxie(dbname)+"Mapper, "+shouzimudaxie(dbname)+"> implements "+shouzimudaxie(dbname)+"Service {";
		str+="\n";
		
		str+="@Resource ";str+="\n";
		str+="private "+shouzimudaxie(dbname)+"Mapper "+dbname+"Mapper;";
		str+="@Override ";str+="\n";
		str+="public List<"+shouzimudaxie(dbname)+"> find"+shouzimudaxie(dbname)+"List() {";
			str+="return "+dbname+"Mapper.find"+shouzimudaxie(dbname)+"List();";
		str+="}";
		
		str+="}";

		return str;
	}
	public static String getMybatis(String dbname,String dbinfo){
		System.out.println("\n");
		System.err.println("----Mybatis----"+shouzimudaxie(dbname)+"Mapper.xml");
		String str="";
		str+="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
		str+="\n";
		str+="<!DOCTYPE mapper PUBLIC \"-//ibatis.apache.org//DTD Mapper 3.0//EN\" \"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd\">";
		str+="\n";
		str+="<mapper namespace=\"com.yd.mapper."+shouzimudaxie(dbname)+"Mapper\">";
		str+="\n";
		
			
		str+="\n";str+="\n";
		str+="<!-- 查询 -->";
		str+="<select id=\"find"+shouzimudaxie(dbname)+"List\" resultType=\"com.yd.pojo."+shouzimudaxie(dbname)+"\">";str+="\n";
					str+="SELECT * FROM "+dbname;
		str+="</select>";
			
		str+="\n";
		str+="</mapper>";
		return str;
	}
	
	
	//转换java类型
	public static String zhuanhuan(String str){
		if(str.trim().toLowerCase().equals("int")){
			return "int";
		}
		if(str.trim().toLowerCase().equals("varchar")){
			return "String";
		}
		if(str.trim().toLowerCase().equals("longtext")){
			return "String";
		}
		if(str.trim().toLowerCase().equals("char")){
			return "String";
		}
		if(str.trim().toLowerCase().equals("datetime")){
			return "String";
		}
		if(str.trim().toLowerCase().equals("decimal")){
			return "BigDecimal";
		}
		return "";
	}
	//首字母大写
	public static String shouzimudaxie(String str){
		 return str.substring(0, 1).toUpperCase() + str.substring(1);
	}
	
}
